package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.ProductSpec;
import com.spzx.product.service.ProductSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 商品规格 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/productSpec")
public class ProductSpecController extends BaseController {
    @Autowired
    private ProductSpecService productSpecService;
    @GetMapping("/list")
    public TableDataInfo getProductSpecList(){
        List<ProductSpec> list = productSpecService.selectProductSpecList();
        return getDataTable(list);
    }
    @PostMapping
    public AjaxResult addProductSpec(@RequestBody ProductSpec productSpec){
        productSpecService.save(productSpec);
        return AjaxResult.success();
    }
    @DeleteMapping("/{id}")
    public AjaxResult deleteProductSpec(@PathVariable Long id){
//        productSpecService.removeById(id);
//        return AjaxResult.success();
        boolean b = productSpecService.removeById(id);
        return b ? AjaxResult.success() : AjaxResult.error();
    }
    @GetMapping("/productSpecList/{id}")
    public AjaxResult getProductSpecList(@PathVariable Long id){
       List<ProductSpec> list =  productSpecService.getProductSpecList(id);
       return AjaxResult.success(list);
    }

}
